#ifndef _ELF_HOOK_H
#define _ELF_HOOK_H

#include <elf.h>
#include <link.h>

typedef struct
{
	const char* pathname;
	ElfW(Addr) base_addr;
	ElfW(Addr) bias_addr;

	ElfW(Ehdr) *ehdr;
	ElfW(Phdr) *phdr;

	ElfW(Dyn) *dyn;   //.dynamic
	ElfW(Word) dyn_sz;

	const char* strtab;  // .dynstr(string-table)
	ElfW(Sym) *symtab;   // .dynsym(symbol-index to string-table's offset)

	ElfW(Addr) relplt;    // .rel.plt
	ElfW(Word) replt_sz;
} elf_t;

int elf_init(elf_t* self, uintptr_t base_addr, const char* pathname);

// 0 -- if *base_addr is elf file header
int elf_check_file_header(uintptr_t base_addr);

ElfW(Phdr) *
elf_get_first_segment_by_type_offset(elf_t* self, ElfW(Word)type, ElfW(Off) offset);

void elf_print(elf_t* self);

elf_t*
read_from_maps();

int elf_hook(elf_t *self, void* new_func, void** old_func);

#endif // _ELF_HOOK_H
